3 namespace MediaWiki\Tests\Revision
;
5 use InvalidArgumentException
;
6 use MediaWiki\MediaWikiServices
;
7 use MediaWiki\Revision\RevisionRecord
;
8 use MediaWiki\Revision\SlotRecord
;
13 * Tests RevisionStore against the intermediate MCR DB schema for use during schema migration.
15 * @covers \MediaWiki\Revision\RevisionStore
17 * @group RevisionStore
22 class McrWriteBothRevisionStoreDbTest
extends RevisionStoreDbTestBase
{
24 use McrWriteBothSchemaOverride
;
26 protected function revisionToRow( Revision
$rev, $options = [ 'page', 'user', 'comment' ] ) {
27 $row = parent
::revisionToRow( $rev, $options );
29 $row->rev_text_id
= (string)$rev->getTextId();
30 $row->rev_content_format
= (string)$rev->getContentFormat();
31 $row->rev_content_model
= (string)$rev->getContentModel();
36 protected function assertRevisionExistsInDatabase( RevisionRecord
$rev ) {
37 // New schema is being written
41 [ 'slot_revision_id' => $rev->getId() ],
48 [ 'content_address' => $rev->getSlot( 'main' )->getAddress() ],
52 // Legacy schema is still being written
54 [ 'revision', 'text' ],
56 [ 'rev_id' => $rev->getId(), 'rev_text_id > 0' ],
59 [ 'text' => [ 'JOIN', [ 'rev_text_id = old_id' ] ] ]
62 parent
::assertRevisionExistsInDatabase( $rev );
66 * @param SlotRecord $a
67 * @param SlotRecord $b
69 protected function assertSameSlotContent( SlotRecord
$a, SlotRecord
$b ) {
70 parent
::assertSameSlotContent( $a, $b );
72 // Assert that the same content ID has been used
73 if ( $a->hasContentId() && $b->hasContentId() ) {
74 $this->assertSame( $a->getContentId(), $b->getContentId() );
78 public function provideInsertRevisionOn_failures() {
79 foreach ( parent
::provideInsertRevisionOn_failures() as $case ) {
83 yield
'slot that is not main slot' => [
86 'main' => new WikitextContent( 'Chicken' ),
87 'lalala' => new WikitextContent( 'Duck' ),
89 'comment' => $this->getRandomCommentStoreComment(),
90 'timestamp' => '20171117010101',
93 new InvalidArgumentException( 'Only the main slot is supported' )
97 public function provideNewMutableRevisionFromArray() {
98 foreach ( parent
::provideNewMutableRevisionFromArray() as $case ) {
102 yield
'Basic array, with page & id' => [
107 'timestamp' => '20171017114835',
108 'user_text' => '111.0.1.2',
110 'minor_edit' => false,
114 'sha1' => 'rdqbbzs3pkhihgbs8qf2q9jsvheag5z',
115 'comment' => 'Goat Comment!',
116 'content_format' => 'text/x-wiki',
117 'content_model' => 'wikitext',
123 * @covers \MediaWiki\Revision\RevisionStore::newRevisionFromArchiveRow
124 * @covers \MediaWiki\Revision\RevisionStore::insertRevisionOn
126 public function testInsertRevisionFromArchiveRow_unmigratedArchiveRow() {
127 // The main purpose of this test is to assert that after reading an archive
128 // row using the old schema it can be inserted into the revision table,
129 // and a slot row is created based on slot emulated from the old-style archive row,
130 // when none such slot row exists yet.
132 $title = $this->getTestPage()->getTitle();
136 [ 'old_text' => 'Just a test', 'old_flags' => 'utf-8' ],
140 $textId = $this->db
->insertId();
143 'ar_minor_edit' => '0',
145 'ar_user_text' => '127.0.0.1',
149 'ar_rev_id' => 112277,
150 'ar_timestamp' => $this->db
->timestamp( '20180101000000' ),
151 'ar_sha1' => 'deadbeef',
152 'ar_page_id' => $title->getArticleID(),
153 'ar_comment_text' => 'just a test',
154 'ar_comment_data' => null,
155 'ar_comment_cid' => null,
156 'ar_content_format' => null,
157 'ar_content_model' => null,
160 'ar_namespace' => $title->getNamespace(),
161 'ar_title' => $title->getDBkey(),
162 'ar_text_id' => $textId,
163 'ar_parent_id' => 112211,
166 $store = MediaWikiServices
::getInstance()->getRevisionStore();
167 $rev = $store->newRevisionFromArchiveRow( $row );
169 // re-insert archived revision
170 $return = $store->insertRevisionOn( $rev, $this->db
);
172 // is the new revision correct?
173 $this->assertRevisionCompleteness( $return );
174 $this->assertRevisionRecordsEqual( $rev, $return );
176 // can we load it from the store?
177 $loaded = $store->getRevisionById( $return->getId() );
178 $this->assertNotNull( $loaded );
179 $this->assertRevisionCompleteness( $loaded );
180 $this->assertRevisionRecordsEqual( $return, $loaded );
182 // can we find it directly in the database?
183 $this->assertRevisionExistsInDatabase( $return );